home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 031a / adg_7_8.zip / CHART.C next >
C/C++ Source or Header  |  1991-02-21  |  11KB  |  294 lines

  1. /****************************************************************************
  2. Module name: Chart.C
  3. Programmer : Jeffrey M. Richter & Elvira Peretsman.
  4. *****************************************************************************/
  5.  
  6. #include "..\nowindws.h"
  7. #undef NOCOLOR
  8. #undef NOGDI
  9. #undef NOKERNEL
  10. #undef NOLSTRING
  11. #undef NOMB
  12. #undef NOMDI
  13. #undef NOMENUS
  14. #undef NONCMESSAGES
  15. #undef NOUSER
  16. #undef NOWINMESSAGES
  17. #undef NOWINOFFSETS
  18. #include <windows.h>
  19.  
  20. #include "mdi.h"
  21.  
  22. static char _szClassName[] = "Chart";
  23.  
  24. // Structure for use with Class Extra Bytes.
  25. typedef struct {
  26.    HMENU hMenu;
  27.    HANDLE hAccelTable;
  28. } CLSEB;
  29.  
  30.  
  31.  
  32. LONG FAR PASCAL ChartProc (HWND hWnd, WORD wMsg, WORD wParam, LONG lParam) {
  33.    static HWND hWndPrevChild = NULL;
  34.    BOOL fCallDefProc = FALSE;
  35.    DWORD dwResult = 0;
  36.    HMENU hMenu;
  37.    WORD wTemp = 0;
  38.    char szBuf[100], szString[100], szCaption[25];
  39.  
  40.    switch (wMsg) {
  41.  
  42.       case WM_CREATE:
  43.          // If this window is first instance created of this class.
  44.          if (GETCLSEB(hWnd, CLSEB, hMenu) == NULL) {
  45.  
  46.             // Initialize the menu and accelerator handles for this class.
  47.             wTemp = LoadMenu(_hInstance, _szClassName);
  48.             SETCLSEB(hWnd, CLSEB, hMenu, (HMENU) wTemp);
  49.             wTemp = LoadAccelerators(_hInstance, _szClassName);
  50.             SETCLSEB(hWnd, CLSEB, hAccelTable, (HANDLE) wTemp);
  51.          }
  52.          break;
  53.  
  54.       case WM_MDIACTIVATE: 
  55.          if (wParam == FALSE) {
  56.             // Child is being deactivated.
  57.             // Reset the previous child so WM_MOUSEACTIVATE will work Ok.
  58.             hWndPrevChild = NULL;
  59.             break;
  60.          }
  61.  
  62.          // Child is being activated.
  63.  
  64.          // Set handle of child being de-activated.
  65.          hWndPrevChild = HIWORD(lParam);
  66.  
  67.          // If this child is being activated and no other child exists,
  68.          // pretend that this child was the last activated child.
  69.          if (hWndPrevChild == NULL) hWndPrevChild = hWnd;
  70.  
  71.          // Set the menu bar and the accelerators to the appropriate ones
  72.          // for this window class.
  73.          ChangeMDIMenu(GETFRAME(hWnd), GetParent(hWnd),
  74.             (HMENU) GETCLSEB(hWnd, CLSEB, hMenu), IDM_WINDOWTILEVERT);
  75.          _hAccelTable = (HANDLE) GETCLSEB(hWnd, CLSEB, hAccelTable);
  76.  
  77.          // For the Status bar at the bottom of the Frame window to be 
  78.          // updated for this child's information.
  79.          InvalidateRect(GETFRAME(hWnd), NULL, TRUE);
  80.          break;
  81.  
  82.       case WM_CLOSE:
  83.          // Make sure that it is OK to close this child window.
  84.          fCallDefProc = (BOOL) SendMessage(hWnd, WM_QUERYENDSESSION, TRUE, 0);
  85.          if (fCallDefProc) SendMessage(hWnd, WM_ENDSESSION, TRUE, 0);
  86.          break;
  87.  
  88.       case WM_QUERYENDSESSION:
  89.          // Prompt user whether to save changes to this document.
  90.          // Usually, a dirty flag (stored in the window's extra bytes
  91.          // is used to determine if it is necessary to ask this question).
  92.  
  93.          // Construct string including the document's name.
  94.          lstrcpy(szBuf, "Save changes to ");
  95.          wTemp = lstrlen(szBuf);
  96.          GetWindowText(hWnd, szBuf + wTemp, sizeof(szBuf) - wTemp);
  97.          lstrcat(szBuf, "?");
  98.  
  99.          // Display message box to user.  The message box should 
  100.          // be system modal if the entire Windows session is being 
  101.          // terminated. (wParam is FALSE).
  102.          wTemp = MessageBox(hWnd, szBuf, _szAppName,
  103.             MB_ICONQUESTION | MB_YESNOCANCEL |
  104.             (wParam ? MB_APPLMODAL : MB_SYSTEMMODAL));
  105.  
  106.          switch (wTemp) {
  107.             case IDYES:
  108.                // Save the document and it's OK to quit.
  109.                dwResult = TRUE;
  110.                break;
  111.  
  112.             case IDNO:
  113.                // Don't save the document and it's OK to quit.
  114.                dwResult = TRUE;
  115.                break;
  116.  
  117.             case IDCANCEL:
  118.                // Don't save the document and it's NOT OK to quit.
  119.                dwResult = FALSE;
  120.                break;
  121.          }
  122.          break;
  123.  
  124.       case WM_ENDSESSION:
  125.          // Do any last minute cleanup during this message.
  126.          break;
  127.  
  128.       case WM_DESTROY:
  129.          // Notify the Frame window that a child has been destroyed after 
  130.          // the child is actually destroyed.  (That's why we use
  131.          // PostMessage instead of SendMessage here).
  132.          PostMessage(GETFRAME(hWnd), FW_MDICHILDDESTROY, hWnd, 0);
  133.          fCallDefProc = TRUE;
  134.          break;
  135.  
  136.       case WM_MOUSEACTIVATE:
  137.          // User clicked the mouse of the Child window.
  138.          // If the mouse is clicked in the window's client area and 
  139.          // the previously active child was NOT this child, the
  140.          // mouse message should be eaten.
  141.          if ((HTCLIENT == LOWORD(lParam)) && (hWnd != hWndPrevChild))
  142.             dwResult = MA_ACTIVATEANDEAT;
  143.          else dwResult = MA_ACTIVATE;
  144.          break;
  145.  
  146.       case WM_SETCURSOR:
  147.          // After an MDI Child becomes active, set the previously active
  148.          // child to this window so that mouse messages will NOT be eaten.
  149.          hWndPrevChild = hWnd;
  150.          fCallDefProc = TRUE;
  151.          break;
  152.  
  153.       case WM_LBUTTONDOWN:
  154.          // Just to let you know when the WM_LBUTTONDOWN message is received.
  155.          MessageBox(hWnd, "WM_LBUTTONDOWN", "Chart", MB_OK);
  156.          break;
  157.  
  158.       case AC_PAINTSTATBAR:
  159.          // Message sent by the Frame window when the status bar needs to 
  160.          // be repainted.
  161.          // wParam = HDC, lParam = LPPAINTSTRUCT to status area in frame.
  162.  
  163.          // Construct status bar string for display.
  164.          LoadString(_hInstance, IDS_CHARTSTATUSBAR, szBuf, sizeof(szBuf));
  165.  
  166.          // Draw the horizontal dividing line separating the Status bar
  167.          // from the MDICLIENT window.
  168.          ((LPPAINTSTRUCT) lParam)->rcPaint.top += (int) 
  169.             SendMessage(GETFRAME(hWnd), FW_DRAWSTATUSDIVIDE, 0,
  170.             (LONG) (LPPAINTSTRUCT) lParam);
  171.  
  172.          // Paint the text in the status bar.
  173.          TextOut((HDC) wParam, 0, ((LPPAINTSTRUCT) lParam)->rcPaint.top,
  174.             szBuf, lstrlen(szBuf));
  175.          break;
  176.  
  177.       case WM_MENUSELECT:
  178.          // Normally, only MDI Child system menu options could appear
  179.          // in this message.  But the Frame window forces WM_MENUSELECT
  180.          // messages to appear here whenever a menu selection occurs.
  181.  
  182.          if (lParam == MAKELONG(-1, 0)) {
  183.             // User has stopped using the menu system.  Notify Frame window
  184.             // so that the status bar will be invalidated.
  185.             SendMessage(GETFRAME(hWnd), FW_SETMENUHELP, 0, 0);
  186.             break;
  187.          }
  188.  
  189.          switch (LOWORD(lParam) & (MF_POPUP | MF_SYSMENU)) {
  190.  
  191.             case 0:
  192.                // wParam is a menu item ID NOT on the Child's system menu.
  193.  
  194.                // If wParam is any of the MDI Children listed in the 
  195.                // "Window" menu, display the same help text.
  196.                if ((wParam > IDM_WINDOWCHILD) && (wParam <= IDM_WINDOWCHILD + 9))
  197.                   wParam = IDM_WINDOWCHILD;
  198.  
  199.                wTemp = IDS_CHARTMENUID + wParam;
  200.                break;
  201.  
  202.             case MF_POPUP:
  203.                // wParam is handle to popup menu.
  204.                // Calculate the index of the top-level menu.
  205.                hMenu = GetMenu(GETFRAME(hWnd));
  206.                wTemp = GetMenuItemCount(hMenu);
  207.                while (wTemp--) 
  208.                   if (GetSubMenu(hMenu, wTemp) == (HMENU) wParam) break;
  209.                wTemp += IDS_CHARTPOPUPID;
  210.                if (!IsZoomed(hWnd)) wTemp++;
  211.                break;
  212.  
  213.             case MF_SYSMENU:
  214.                // wParam is menu item ID from MDI Child's system menu.
  215.                wTemp = IDS_CHARTMENUID + ((wParam & 0x0FFF) >> 4);
  216.                break;
  217.  
  218.             case MF_POPUP | MF_SYSMENU:
  219.                // wParam is handle to MDI Child's sys menu.
  220.                wTemp = IDS_CHARTPOPUPID;
  221.                break;
  222.          }
  223.          // Tell the Frame that this window should display the help
  224.          // text and the identifier for the help text.
  225.          SendMessage(GETFRAME(hWnd), FW_SETMENUHELP, hWnd, wTemp);
  226.          break;
  227.  
  228.       case WM_ENTERIDLE:
  229.          // User stopped moving around in the help system, make the Frame
  230.          // believe that it received this message directly.
  231.          SendMessage(GETFRAME(hWnd), wMsg, wParam, lParam);
  232.          break;
  233.  
  234.       case AW_PAINTMENUHELP:
  235.          // Message sent from Frame window to notify child that it should
  236.          // paint the status bar text for the last highlighted menu item.
  237.          // lParam = LPPAINTSTRUCT of Frame's status bar.
  238.  
  239.          // Ask the Frame window what the last selected menu ID was.
  240.          // This value was sent to the frame by this window during the 
  241.          // processing for the WM_MENUSELECT message.
  242.          dwResult = SendMessage(GETFRAME(hWnd), FW_GETMENUHELP, 0, 0);
  243.  
  244.          // Draw the horizontal dividing line separating the Status bar
  245.          // from the MDICLIENT window.
  246.          ((LPPAINTSTRUCT) lParam)->rcPaint.top += (int) 
  247.             SendMessage(GETFRAME(hWnd), FW_DRAWSTATUSDIVIDE, 0,
  248.             (LONG) (LPPAINTSTRUCT) lParam);
  249.  
  250.          // Construct the string that is to be displayed.
  251.          LoadString(_hInstance, LOWORD(dwResult), szString, sizeof(szString));
  252.          GetWindowText(hWnd, szCaption, sizeof(szCaption));
  253.          wsprintf(szBuf, szString, (LPSTR) szCaption);
  254.  
  255.          // Paint the menu help text in the status bar.
  256.          TextOut(((LPPAINTSTRUCT) lParam)->hdc,
  257.             0, ((LPPAINTSTRUCT) lParam)->rcPaint.top, szBuf, lstrlen(szBuf));
  258.          break;
  259.  
  260.       case WM_COMMAND:
  261.          // Any menu options NOT processed by the Frame are passed to the
  262.          // active child.
  263.          MessageBox(hWnd, "Option not implemented.", _szAppName, MB_OK);
  264.          break;
  265.  
  266.       default: fCallDefProc = TRUE; break;
  267.    }
  268.  
  269.    if (fCallDefProc)
  270.       dwResult = DefMDIChildProc(hWnd, wMsg, wParam, lParam);
  271.  
  272.    return(dwResult);
  273. }
  274.  
  275.  
  276. BOOL FAR PASCAL RegisterChartWndClass (void) {
  277.    WNDCLASS wc;
  278.  
  279.    wc.style          = 0;
  280.    wc.lpfnWndProc    = ChartProc;
  281.  
  282.    // Number of class extra bytes used by structure.
  283.    wc.cbClsExtra     = sizeof(CLSEB);
  284.  
  285.    wc.cbWndExtra     = 0;
  286.    wc.hInstance      = _hInstance;
  287.    wc.hIcon          = LoadIcon(_hInstance, _szClassName);
  288.    wc.hCursor        = LoadCursor(NULL, IDC_ARROW);
  289.    wc.hbrBackground  = COLOR_WINDOW + 1;
  290.    wc.lpszMenuName   = NULL;
  291.    wc.lpszClassName  = _szClassName;
  292.    return(RegisterClass(&wc));
  293. }
  294.